{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bba1f0fe-f0cc-4731-b363-d5592a0a957f",
   "metadata": {},
   "source": [
    "## 今天我们将使用Strands Agents 5分钟内带你完成，第一个AI Agent"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0f13296b-a1de-4d7e-afe9-a2f4aed1fba5",
   "metadata": {},
   "source": [
    "## 核心概念\n",
    "\n",
    "Strands Agents SDK 是亚马逊云科技推出的基于模型驱动的AI Agent SDK，几行代码就可以快速构建和运行Agentic AI 应用。它包含以下核心组件：\n",
    "#### **模型（Model）**\n",
    "  - 作为Agent的推理引擎，支持多个模型平台，包括Amazon Bedrock, Anthropic, LiteLLM, Llama API, Ollama以及OpenAI等等\n",
    "  - 示例模型配置：\n",
    "    ```\n",
    "    from strands.models import BedrockModel\n",
    "    model = BedrockModel(model_id=\"us.anthropic.claude-3-7-sonnet-20250219-v1:0\", region_name='us-east-1')\n",
    "    ```  \n",
    "    \n",
    "\n",
    "#### **工具（Tools）**\n",
    "  - 预置20+工具（计算器、HTTP请求、记忆以及多模型协作等）\n",
    "  - 使用`@tool`装饰器快速集成自定义函数：\n",
    "    ```\n",
    "    from strands import tool\n",
    "    @tool\n",
    "    def file_analyzer(path: str) -> dict:\n",
    "        \"\"\"文件分析工具\"\"\"\n",
    "        # 实现文件解析逻辑\n",
    "        return analysis_result\n",
    "    ```\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#### **提示词（Prompt）**\n",
    "  - 系统提示定义Agent行为准则：\n",
    "    ```\n",
    "    SYSTEM_PROMPT = \"\"\"你是一个数据分析专家，使用工具处理数据并生成可视化报告：\n",
    "    1. 优先使用pandas进行数据清洗\n",
    "    2. 使用matplotlib创建交互式图表\n",
    "    3. 输出Markdown格式报告\"\"\"\n",
    "    ```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "8490df5c-8e7b-4f7c-8b5e-e2f057e4debb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: strands-agents in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (0.2.1)\n",
      "Requirement already satisfied: boto3<2.0.0,>=1.26.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (1.38.38)\n",
      "Requirement already satisfied: botocore<2.0.0,>=1.29.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (1.38.38)\n",
      "Requirement already satisfied: docstring-parser<1.0,>=0.15 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (0.16)\n",
      "Requirement already satisfied: mcp<2.0.0,>=1.8.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (1.11.0)\n",
      "Requirement already satisfied: opentelemetry-api<2.0.0,>=1.30.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (1.35.0)\n",
      "Requirement already satisfied: opentelemetry-sdk<2.0.0,>=1.30.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (1.35.0)\n",
      "Requirement already satisfied: pydantic<3.0.0,>=2.0.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (2.9.2)\n",
      "Requirement already satisfied: typing-extensions<5.0.0,>=4.13.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (4.14.0)\n",
      "Requirement already satisfied: watchdog<7.0.0,>=6.0.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents) (6.0.0)\n",
      "Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from boto3<2.0.0,>=1.26.0->strands-agents) (1.0.1)\n",
      "Requirement already satisfied: s3transfer<0.14.0,>=0.13.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from boto3<2.0.0,>=1.26.0->strands-agents) (0.13.0)\n",
      "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from botocore<2.0.0,>=1.29.0->strands-agents) (2.9.0.post0)\n",
      "Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from botocore<2.0.0,>=1.29.0->strands-agents) (2.4.0)\n",
      "Requirement already satisfied: anyio>=4.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (4.9.0)\n",
      "Requirement already satisfied: httpx-sse>=0.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (0.4.1)\n",
      "Requirement already satisfied: httpx>=0.27 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (0.28.1)\n",
      "Requirement already satisfied: jsonschema>=4.20.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (4.24.0)\n",
      "Requirement already satisfied: pydantic-settings>=2.5.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (2.10.1)\n",
      "Requirement already satisfied: python-multipart>=0.0.9 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (0.0.20)\n",
      "Requirement already satisfied: sse-starlette>=1.6.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (2.4.1)\n",
      "Requirement already satisfied: starlette>=0.27 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (0.46.2)\n",
      "Requirement already satisfied: uvicorn>=0.23.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents) (0.34.3)\n",
      "Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from opentelemetry-api<2.0.0,>=1.30.0->strands-agents) (6.11.0)\n",
      "Requirement already satisfied: zipp>=0.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api<2.0.0,>=1.30.0->strands-agents) (3.23.0)\n",
      "Requirement already satisfied: opentelemetry-semantic-conventions==0.56b0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from opentelemetry-sdk<2.0.0,>=1.30.0->strands-agents) (0.56b0)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic<3.0.0,>=2.0.0->strands-agents) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.23.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic<3.0.0,>=2.0.0->strands-agents) (2.23.4)\n",
      "Requirement already satisfied: six>=1.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<2.0.0,>=1.29.0->strands-agents) (1.17.0)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from anyio>=4.5->mcp<2.0.0,>=1.8.0->strands-agents) (1.3.0)\n",
      "Requirement already satisfied: idna>=2.8 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from anyio>=4.5->mcp<2.0.0,>=1.8.0->strands-agents) (3.10)\n",
      "Requirement already satisfied: sniffio>=1.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from anyio>=4.5->mcp<2.0.0,>=1.8.0->strands-agents) (1.3.1)\n",
      "Requirement already satisfied: certifi in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents) (2025.6.15)\n",
      "Requirement already satisfied: httpcore==1.* in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents) (1.0.9)\n",
      "Requirement already satisfied: h11>=0.16 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents) (0.16.0)\n",
      "Requirement already satisfied: attrs>=22.2.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents) (25.3.0)\n",
      "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents) (2025.4.1)\n",
      "Requirement already satisfied: referencing>=0.28.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents) (0.36.2)\n",
      "Requirement already satisfied: rpds-py>=0.7.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents) (0.25.1)\n",
      "Requirement already satisfied: python-dotenv>=0.21.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic-settings>=2.5.2->mcp<2.0.0,>=1.8.0->strands-agents) (1.1.1)\n",
      "Requirement already satisfied: typing-inspection>=0.4.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic-settings>=2.5.2->mcp<2.0.0,>=1.8.0->strands-agents) (0.4.1)\n",
      "Requirement already satisfied: click>=7.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from uvicorn>=0.23.1->mcp<2.0.0,>=1.8.0->strands-agents) (8.1.8)\n",
      "Requirement already satisfied: strands-agents-tools in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (0.1.8)\n",
      "Requirement already satisfied: aws-requests-auth<0.5.0,>=0.4.3 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (0.4.3)\n",
      "Requirement already satisfied: colorama<0.5.0,>=0.4.6 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (0.4.6)\n",
      "Requirement already satisfied: dill<0.5.0,>=0.4.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (0.4.0)\n",
      "Requirement already satisfied: pillow<12.0.0,>=11.2.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (11.2.1)\n",
      "Requirement already satisfied: prompt-toolkit<4.0.0,>=3.0.51 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (3.0.51)\n",
      "Requirement already satisfied: pyjwt<3.0.0,>=2.10.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (2.10.1)\n",
      "Requirement already satisfied: rich<15.0.0,>=14.0.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (14.0.0)\n",
      "Requirement already satisfied: slack-bolt<2.0.0,>=1.23.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (1.23.0)\n",
      "Requirement already satisfied: strands-agents<1.0.0,>=0.1.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (0.2.1)\n",
      "Requirement already satisfied: sympy<2.0.0,>=1.12.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (1.14.0)\n",
      "Requirement already satisfied: tenacity<10.0.0,>=9.1.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (9.1.2)\n",
      "Requirement already satisfied: watchdog<7.0.0,>=6.0.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents-tools) (6.0.0)\n",
      "Requirement already satisfied: requests>=0.14.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from aws-requests-auth<0.5.0,>=0.4.3->strands-agents-tools) (2.32.4)\n",
      "Requirement already satisfied: wcwidth in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from prompt-toolkit<4.0.0,>=3.0.51->strands-agents-tools) (0.2.13)\n",
      "Requirement already satisfied: markdown-it-py>=2.2.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from rich<15.0.0,>=14.0.0->strands-agents-tools) (3.0.0)\n",
      "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from rich<15.0.0,>=14.0.0->strands-agents-tools) (2.19.1)\n",
      "Requirement already satisfied: typing-extensions<5.0,>=4.0.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from rich<15.0.0,>=14.0.0->strands-agents-tools) (4.14.0)\n",
      "Requirement already satisfied: slack_sdk<4,>=3.35.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from slack-bolt<2.0.0,>=1.23.0->strands-agents-tools) (3.36.0)\n",
      "Requirement already satisfied: boto3<2.0.0,>=1.26.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.38.38)\n",
      "Requirement already satisfied: botocore<2.0.0,>=1.29.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.38.38)\n",
      "Requirement already satisfied: docstring-parser<1.0,>=0.15 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.16)\n",
      "Requirement already satisfied: mcp<2.0.0,>=1.8.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.11.0)\n",
      "Requirement already satisfied: opentelemetry-api<2.0.0,>=1.30.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.35.0)\n",
      "Requirement already satisfied: opentelemetry-sdk<2.0.0,>=1.30.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.35.0)\n",
      "Requirement already satisfied: pydantic<3.0.0,>=2.0.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (2.9.2)\n",
      "Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from boto3<2.0.0,>=1.26.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.0.1)\n",
      "Requirement already satisfied: s3transfer<0.14.0,>=0.13.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from boto3<2.0.0,>=1.26.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.13.0)\n",
      "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from botocore<2.0.0,>=1.29.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (2.9.0.post0)\n",
      "Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from botocore<2.0.0,>=1.29.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (2.4.0)\n",
      "Requirement already satisfied: anyio>=4.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (4.9.0)\n",
      "Requirement already satisfied: httpx-sse>=0.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.4.1)\n",
      "Requirement already satisfied: httpx>=0.27 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.28.1)\n",
      "Requirement already satisfied: jsonschema>=4.20.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (4.24.0)\n",
      "Requirement already satisfied: pydantic-settings>=2.5.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (2.10.1)\n",
      "Requirement already satisfied: python-multipart>=0.0.9 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.0.20)\n",
      "Requirement already satisfied: sse-starlette>=1.6.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (2.4.1)\n",
      "Requirement already satisfied: starlette>=0.27 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.46.2)\n",
      "Requirement already satisfied: uvicorn>=0.23.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.34.3)\n",
      "Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from opentelemetry-api<2.0.0,>=1.30.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (6.11.0)\n",
      "Requirement already satisfied: zipp>=0.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api<2.0.0,>=1.30.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (3.23.0)\n",
      "Requirement already satisfied: opentelemetry-semantic-conventions==0.56b0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from opentelemetry-sdk<2.0.0,>=1.30.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.56b0)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic<3.0.0,>=2.0.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.23.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic<3.0.0,>=2.0.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (2.23.4)\n",
      "Requirement already satisfied: six>=1.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<2.0.0,>=1.29.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.17.0)\n",
      "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from sympy<2.0.0,>=1.12.0->strands-agents-tools) (1.3.0)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from anyio>=4.5->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.3.0)\n",
      "Requirement already satisfied: idna>=2.8 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from anyio>=4.5->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (3.10)\n",
      "Requirement already satisfied: sniffio>=1.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from anyio>=4.5->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.3.1)\n",
      "Requirement already satisfied: certifi in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (2025.6.15)\n",
      "Requirement already satisfied: httpcore==1.* in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.0.9)\n",
      "Requirement already satisfied: h11>=0.16 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.16.0)\n",
      "Requirement already satisfied: attrs>=22.2.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (25.3.0)\n",
      "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (2025.4.1)\n",
      "Requirement already satisfied: referencing>=0.28.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.36.2)\n",
      "Requirement already satisfied: rpds-py>=0.7.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.25.1)\n",
      "Requirement already satisfied: mdurl~=0.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich<15.0.0,>=14.0.0->strands-agents-tools) (0.1.2)\n",
      "Requirement already satisfied: python-dotenv>=0.21.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic-settings>=2.5.2->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (1.1.1)\n",
      "Requirement already satisfied: typing-inspection>=0.4.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic-settings>=2.5.2->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (0.4.1)\n",
      "Requirement already satisfied: charset_normalizer<4,>=2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from requests>=0.14.0->aws-requests-auth<0.5.0,>=0.4.3->strands-agents-tools) (3.4.2)\n",
      "Requirement already satisfied: click>=7.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from uvicorn>=0.23.1->mcp<2.0.0,>=1.8.0->strands-agents<1.0.0,>=0.1.0->strands-agents-tools) (8.1.8)\n",
      "Requirement already satisfied: strands-agents[openai] in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (0.2.1)\n",
      "Requirement already satisfied: boto3<2.0.0,>=1.26.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (1.38.38)\n",
      "Requirement already satisfied: botocore<2.0.0,>=1.29.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (1.38.38)\n",
      "Requirement already satisfied: docstring-parser<1.0,>=0.15 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (0.16)\n",
      "Requirement already satisfied: mcp<2.0.0,>=1.8.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (1.11.0)\n",
      "Requirement already satisfied: opentelemetry-api<2.0.0,>=1.30.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (1.35.0)\n",
      "Requirement already satisfied: opentelemetry-sdk<2.0.0,>=1.30.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (1.35.0)\n",
      "Requirement already satisfied: pydantic<3.0.0,>=2.0.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (2.9.2)\n",
      "Requirement already satisfied: typing-extensions<5.0.0,>=4.13.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (4.14.0)\n",
      "Requirement already satisfied: watchdog<7.0.0,>=6.0.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (6.0.0)\n",
      "Requirement already satisfied: openai<2.0.0,>=1.68.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from strands-agents[openai]) (1.95.1)\n",
      "Requirement already satisfied: jmespath<2.0.0,>=0.7.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from boto3<2.0.0,>=1.26.0->strands-agents[openai]) (1.0.1)\n",
      "Requirement already satisfied: s3transfer<0.14.0,>=0.13.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from boto3<2.0.0,>=1.26.0->strands-agents[openai]) (0.13.0)\n",
      "Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from botocore<2.0.0,>=1.29.0->strands-agents[openai]) (2.9.0.post0)\n",
      "Requirement already satisfied: urllib3!=2.2.0,<3,>=1.25.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from botocore<2.0.0,>=1.29.0->strands-agents[openai]) (2.4.0)\n",
      "Requirement already satisfied: anyio>=4.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (4.9.0)\n",
      "Requirement already satisfied: httpx-sse>=0.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.4.1)\n",
      "Requirement already satisfied: httpx>=0.27 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.28.1)\n",
      "Requirement already satisfied: jsonschema>=4.20.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (4.24.0)\n",
      "Requirement already satisfied: pydantic-settings>=2.5.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (2.10.1)\n",
      "Requirement already satisfied: python-multipart>=0.0.9 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.0.20)\n",
      "Requirement already satisfied: sse-starlette>=1.6.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (2.4.1)\n",
      "Requirement already satisfied: starlette>=0.27 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.46.2)\n",
      "Requirement already satisfied: uvicorn>=0.23.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.34.3)\n",
      "Requirement already satisfied: distro<2,>=1.7.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from openai<2.0.0,>=1.68.0->strands-agents[openai]) (1.9.0)\n",
      "Requirement already satisfied: jiter<1,>=0.4.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from openai<2.0.0,>=1.68.0->strands-agents[openai]) (0.10.0)\n",
      "Requirement already satisfied: sniffio in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from openai<2.0.0,>=1.68.0->strands-agents[openai]) (1.3.1)\n",
      "Requirement already satisfied: tqdm>4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from openai<2.0.0,>=1.68.0->strands-agents[openai]) (4.67.1)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from anyio>=4.5->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (1.3.0)\n",
      "Requirement already satisfied: idna>=2.8 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from anyio>=4.5->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (3.10)\n",
      "Requirement already satisfied: certifi in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (2025.6.15)\n",
      "Requirement already satisfied: httpcore==1.* in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (1.0.9)\n",
      "Requirement already satisfied: h11>=0.16 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.27->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.16.0)\n",
      "Requirement already satisfied: importlib-metadata<8.8.0,>=6.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from opentelemetry-api<2.0.0,>=1.30.0->strands-agents[openai]) (6.11.0)\n",
      "Requirement already satisfied: zipp>=0.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from importlib-metadata<8.8.0,>=6.0->opentelemetry-api<2.0.0,>=1.30.0->strands-agents[openai]) (3.23.0)\n",
      "Requirement already satisfied: opentelemetry-semantic-conventions==0.56b0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from opentelemetry-sdk<2.0.0,>=1.30.0->strands-agents[openai]) (0.56b0)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic<3.0.0,>=2.0.0->strands-agents[openai]) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.23.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic<3.0.0,>=2.0.0->strands-agents[openai]) (2.23.4)\n",
      "Requirement already satisfied: six>=1.5 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from python-dateutil<3.0.0,>=2.1->botocore<2.0.0,>=1.29.0->strands-agents[openai]) (1.17.0)\n",
      "Requirement already satisfied: attrs>=22.2.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (25.3.0)\n",
      "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (2025.4.1)\n",
      "Requirement already satisfied: referencing>=0.28.4 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.36.2)\n",
      "Requirement already satisfied: rpds-py>=0.7.1 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from jsonschema>=4.20.0->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.25.1)\n",
      "Requirement already satisfied: python-dotenv>=0.21.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic-settings>=2.5.2->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (1.1.1)\n",
      "Requirement already satisfied: typing-inspection>=0.4.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from pydantic-settings>=2.5.2->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (0.4.1)\n",
      "Requirement already satisfied: click>=7.0 in /home/ec2-user/anaconda3/envs/python3/lib/python3.10/site-packages (from uvicorn>=0.23.1->mcp<2.0.0,>=1.8.0->strands-agents[openai]) (8.1.8)\n"
     ]
    }
   ],
   "source": [
    "!pip install strands-agents\n",
    "!pip install strands-agents-tools\n",
    "!pip install strands-agents[openai]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "48525e14-8dd6-4443-aa69-c37fce8bbca6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# first_agent.py\n",
    "import sys\n",
    "from strands import Agent\n",
    "from strands_tools import current_time, http_request\n",
    "from strands.models.openai import OpenAIModel\n",
    "import logging\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "bb28f0de-cf3d-45dd-ad21-073750ddfb2c",
   "metadata": {},
   "outputs": [],
   "source": [
    "logging.getLogger(\"strands\").setLevel(logging.INFO)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "e56df754-978f-4173-bc48-3b811da93959",
   "metadata": {},
   "outputs": [],
   "source": [
    "model = OpenAIModel(\n",
    "    client_args={\n",
    "        \"api_key\": ##\"此处填写硅基流动key\",\n",
    "         \"base_url\": \"https://api.siliconflow.cn\"\n",
    "    },\n",
    "    # **model_config\n",
    "    model_id=\"deepseek-ai/DeepSeek-V3\",\n",
    "    params={\n",
    "        \"max_tokens\": 10000,\n",
    "        \"temperature\": 0.7,\n",
    "    }\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "b8b31fc7-48b9-4e58-b33c-13937b8bac15",
   "metadata": {},
   "outputs": [],
   "source": [
    "agent = Agent(\n",
    "    system_prompt = \"\"\"你是一个生活助手，运用科学的知识回答各种问题。\"\"\",\n",
    "    model=model,\n",
    "    tools=[current_time, http_request]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "6812ec36-89c0-42d7-930c-2eb8c4b38485",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Tool #1: current_time\n",
      "现在是北京时间 13:39。"
     ]
    }
   ],
   "source": [
    "query = \"\"\"\n",
    "请回答以下问题:现在北京时间是几点?\n",
    "\"\"\"\n",
    "response = agent(query)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "76f5bcd2-348d-4abe-a9da-9dbd3f53aa65",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "梅雨（又称“霉雨”）是指每年春夏之交，在东亚地区（如中国长江中下游、日本、韩国等地）出现的一段持续阴雨天气现象。梅雨的形成主要与副热带高压和北方冷空气的交汇有关，导致暖湿气流与冷空气相遇，产生长时间的阴雨天气。\n",
      "\n",
      "### 梅雨的特点：\n",
      "1. **持续时间长**：通常持续一个月左右，具体时间因年份和地区而异。\n",
      "2. **雨量集中**：降水频繁，且多为连绵细雨，偶尔也会有暴雨。\n",
      "3. **高湿度**：空气湿度大，物品容易发霉，因此也被称为“霉雨”。\n",
      "4. **气温适中**：既不像夏季炎热，也不像冬季寒冷，但闷热感较强。\n",
      "\n",
      "### 梅雨的影响：\n",
      "- **农业**：对水稻等作物的生长有利，但过多的雨水可能导致洪涝灾害。\n",
      "- **生活**：潮湿的环境容易滋生霉菌，影响衣物、食品的保存。\n",
      "- **交通**：持续阴雨可能导致道路积水或交通不便。\n",
      "\n",
      "在中国，梅雨通常出现在6月至7月，是东亚季风气候的典型现象之一。"
     ]
    }
   ],
   "source": [
    "\n",
    "\n",
    "query = \"\"\"\n",
    "请回答以下问题:根据百科网站, 梅雨是什么意思?\n",
    "\"\"\"\n",
    "response = agent(query)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "239467e3-6ae0-41f5-bbf1-2d7cd55b4be6",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "conda_python3",
   "language": "python",
   "name": "conda_python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
